/**
 * 登录模块，提供登录相关业务功能
 * 
 * @Date: 2016-1-21
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */
define(["jquery", "datagridServ","sysmanMain", "bizProto","btnServ","msgServ","flowInit","supplySelect"],
		function($,datagridServ, sysmanMain, bizProto,btnServ,msgServ,flowInit,supplySelect) {

		'use strict';

		var _typeUrl = '/dictionary/getTree.action',_rootpath,
			item_code_dic_id = 24,
			rootId = 'panel-supply-badinfo',
			edit_window_id='supply-badinfo-win',
			el_width = 300,el_big_width=674,window_width=900,window_height=600
		
		var public_method ={
			
			/**
			 * 初始化新增页面
			 * @param _options.record 列表选中行
			 * @param _options.form 页面form对象
			 */
			initElement:function(_options){
				$('#' +edit_window_id +' #supply_name').textbox({
					onClickButton : function(data) {
						supplySelect.openPage({
							id : edit_window_id
									+ ' #supply_id',
							value : edit_window_id
									+ ' #supply_name',
							singleSelect: true
						})
					}
				})
			},
			
			closeWindow:function(){
				$('#'+edit_window_id).empty()
				var _moduleConfig = sysmanMain.getCurrentModuConfig();
				_moduleConfig.initParam = {editable:true};
				sysmanMain.setCurrentModuConfig(_moduleConfig);
			},
			/**
			 * @param _options.rootId
			 * @param _options.conditionSelector
			 * @param _options.
			 */
			initList:function(_options){
				private_method.initCondition(_options)
			},
			reCreateField:function(_options){
				private_method.reCreateField(_options)
			},
			rowDblClick:function(index,row){
				private_method.rowDblClick(index,row)
			}
			
		}
		var private_method = {
			
			rowDblClick:function(index,row){
				
				var editWindow = edit_window_id;
				var _param = {}
				var _moduleConfig = sysmanMain.getCurrentModuConfig();
				if(!_moduleConfig){
					_moduleConfig={}
				}
				
				var flow_state_el = $('#'+rootId+' form.condition-form #flow_state')
				var flow_state_value = $(flow_state_el).combobox('getValue')
				if(flow_state_value && flow_state_value==='finished'){
					_param.editable = false
				}else{
					_param.editable = true
				}
				_moduleConfig.initParam = _param
				sysmanMain.setCurrentModuConfig(_moduleConfig)
				
				var $grid= $('#'+rootId +" table.dg-list");
				var $edit_window = $('#' + editWindow);
				var _url =  '/'+sysmanMain.getRootPath() +'/supplybadinfo/query/editPage.action';
				var _dgparam = {grid:$grid,window:$edit_window,href:_url,width:window_width,height:window_height,flag:true,existCheckElement:'form'}
								
				_dgparam.onClose=public_method.closeWindow
				
				datagridServ.windowEdit(_dgparam);
			},
			/**
			 * 初始化条件查询框
			 * @param _options.rootId 窗口根节点id
			 * @param _options.conditionSelector 条件框节点选择器
			 */
			initCondition:function(_options){
				if(window.console){
					console.info('recipel init loaded and starting...')
				}
				
				flowInit.initList(_options)
			
			}
		}
			
			return public_method;

		});